/// <reference types="vitest/config" />
import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import { VantResolver } from 'unplugin-vue-components/resolvers'
import { createHtmlPlugin } from 'vite-plugin-html'

import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import path from 'path'

// 配置mock => 将来我们在那里提供假接口
import { viteMockServe } from 'vite-plugin-mock'

// https://vitejs.dev/config/
export default defineConfig({
  base: '/',
  test: {
    environment: 'happy-dom'
  },
  plugins: [
    viteMockServe({
      mockPath: './src/mock',
      // localEnabled: true
      enable: true
    }),
    createHtmlPlugin(),
    vue(),
    // 自动导入的插件
    Components({
      // 他在帮你导入组件时 会多导入一份类型文件(取消)
      dts: false,
      // 他在帮你导入组件时 会多导入一份样式文件(取消)
      resolvers: [VantResolver({ importStyle: false })]
    }),
    // 自动打包svg精灵图插件
    createSvgIconsPlugin({
      // 指定将来打包的svg图标文件夹
      // eslint-disable-next-line no-undef
      iconDirs: [path.resolve(process.cwd(), 'src/icons')]
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})
